/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.sdgakj.repository;

import com.sdgakj.entity.Person;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

public interface PersonDao extends PagingAndSortingRepository<Person, Long>,JpaSpecificationExecutor<Person> {

    @Query(value = "select * from f_person where family_id=?1", nativeQuery = true) /*之前是where family_id=?1*/
    List<Person> getPersonsByFamilyId(Long fId);

   /* @Query(value = "select * from f_person where id=?1 " ,nativeQuery = true)*/
    List<Person> getPersonsById(Long id,Integer page,Integer pageSize);

    @Query(value = "select * from f_person where family_id=?1",nativeQuery = true)
    List<Person> getPersonBrotherByFaterId(Long id);

    @Query(value = "select  * from f_person where family_id=?1 and id=?2",nativeQuery = true)
    Person getPersonByFamilyId(Long familyId,Long id);

    @Query(value = "select * from f_person where user_id=?1",nativeQuery = true)
    Person getPersonByUserId(Long userId);

    @Query(value = "select * from f_person where f=?1",nativeQuery = true)
    List<Person> getChildrensByFather(Long fatherId);

    @Query(value = "select * from f_person where m=?1",nativeQuery = true)
    List<Person> getChildrensByMathar(Long matherId);

    @Query(value = "select count(1) from f_person",nativeQuery = true)
    Long getPersonCount();

    @Query(value = "select count(1) from f_person where s =M",nativeQuery = true)
    Long personsm();

    @Query(value = "select count(1) from f_person where s =F",nativeQuery = true)
    Long personsf();

    @Query(value = "select count(1) from f_person where alive =0",nativeQuery = true)
    Long personalive();

    @Query(value = "select count(1) from f_person where alive =1",nativeQuery = true)
    Long personnalive();


}
